<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 武露斌
  Date: 2021/10/22
  Time: 19:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-1.8.2.min.js"></script>
    <script src="../../js/fileupload.js"></script>
    <link rel="stylesheet" href="../../css/css.css">
    <link rel="stylesheet" href="../../css/img.css">
</head>
<body>

<form method="post" action="list.do">
    <input type="hidden" name="pageNum"><br>
    标题：<input type="text" name="title" value="${map.title}">
    内容：<input type="text" name="content" value="${map.content}">
    标签：<input type="text" name="tname" value="${map.tname}">
    <input type="submit" value="查询">
    <input type="button" value="刷新" onclick="sx()">
</form>

<table>
    <tr>
        <th></th>
        <th>编号</th>
        <th>文章标题</th>
        <th>文章图片</th>
        <th>文章内容</th>
        <th>创建时间</th>
        <th>标签名称</th>
        <th>
            <input type="button" value="添加" onclick="add()">
        </th>
    </tr>
    <c:forEach items="${pageInfo.list}" var="a">
        <tr>
            <td>
                <input type="checkbox" name="cc" value="${a.eid}">
            </td>
            <td>${a.eid}</td>
            <td>${a.title}</td>
<%--            <td>${a.img}</td>--%>
            <td>
                <img src="${a.img}" width="60px">
            </td>
            <td>${a.content}</td>
            <td>${a.statime}</td>
            <td>${a.tname}</td>
            <td>
                <input type="button" value="删除" onclick="del(${a.eid})">
                <input type="button" value="编辑" onclick="upda(${a.eid})">
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="20">
            <input type="button" value="全选" onclick="qx()">
            <input type="button" value="全不选" onclick="qbx()">
            <input type="button" value="反选" onclick="fx()">
            <input type="button" value="批量删除" onclick="dels()">
            <input type="button" value="首页" onclick="fy(1)">
            <input type="button" value="上一页" onclick="fy(${pageInfo.isFirstPage?1:pageInfo.prePage})">
            <input type="button" value="下一页" onclick="fy(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">
            <input type="button" value="尾页" onclick="fy(${pageInfo.pages})">
        </td>
    </tr>
</table>

</body>
</html>

<script>

    function qx() {
        $("[name='cc']").prop("checked",true)
    }
    function qbx() {
        $("[name='cc']").prop("checked",false)
    }
    function fx() {
        $("[name='cc']").each(function () {
            $(this).prop("checked",!$(this).prop("checked"))
        })
    }

    function dels() {
        var eids=$("[name='cc']:checked").map(function () {
            return $(this).val()
        }).get().toString()

        if(confirm("确定要删除ID为"+eids+"书籍吗？")){
            $.ajax({
                url:"dels.do",
                data: {"eids":eids},
                type: "post",
                dataType: "json",
                success:function (data) {
                    if (data>0){
                        alert("删除成功")
                        location="list.do"
                    }else{
                        alert("删除失败")
                    }
                }
            })
        }else{
            alert("已经取消")
        }


    }


    function del(eid) {
        if(confirm("确定要删除ID为"+eid+"的书籍吗？")){
            $.ajax({
                url:"del.do",
                data:{"eid":eid},
                type:"post",
                dataType:"json",
                success:function (data) {
                    if (data>0){
                        alert("删除成功")
                        location="list.do"
                    }else{
                        alert("删除失败")
                    }
                }
            })
        }else{
            alert("已经取消")
        }
    }

    function fy(pageNum) {
        $("[name='pageNum']").val(pageNum)
        $("form").submit();
    }

    function sx() {
        location="list.do"
    }

    function add() {
        location="addto.do"
    }

    function upda(eid) {
        location="updato.do?eid="+eid;
    }
</script>























